<%@ Page Language="C#" MasterPageFile="~/admin/HO/HOMP.master" AutoEventWireup="true"
    CodeFile="ManagementBranchesOnRoute.aspx.cs" Inherits="admin_HO_ManagementBranchesOnRoute"
    Title="Branches on Routes" %>

<asp:Content ID="Content1" ContentPlaceHolderID="body_page" runat="Server"><asp:Button id="Button4" onclick="Button4_Click" runat="server" Text="Create Branches on routes" EnableViewState="False" CausesValidation="False">
                    </asp:Button>&nbsp;
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Search branches on route" CausesValidation="False" EnableViewState="False" />
                    <asp:Label ID="lblThongbao" runat="server"></asp:Label>
    <asp:Panel ID="pnCreate" runat="server" Width="100%" Visible="False">
        <table class="table2" style="width: 100%">
            <tr>
                <td style="width: 30%">
                    Routes</td>
                <td style="width: 714px">
                    <asp:DropDownList ID="ddlRoutes" runat="server" Width="100%">
                    </asp:DropDownList>
                </td>
            </tr>
            
            <tr>
                <td style="height: 27px">
                    Branches</td>
                <td style="width: 714px; height: 27px;">
                    <asp:DropDownList ID="ddlBranches" runat="server" Width="100%" DataSourceID="dsBranches" DataTextField="BranchName" DataValueField="BranchID">
                    </asp:DropDownList><asp:SqlDataSource ID="dsBranches" runat="server" ConnectionString="<%$ ConnectionStrings:ketnoi2 %>"
                        SelectCommand="SELECT * FROM [Branches]"></asp:SqlDataSource>
                    &nbsp;
                </td>
            </tr>
            <tr><td>Number</td>
            <td><asp:TextBox ID="txtNumber" runat="server" Width="56px"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtNumber"
                    ErrorMessage="Please input number" Display="Dynamic"></asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtNumber"
                    Display="Dynamic" ErrorMessage="Only number" ValidationExpression="\d{0,999999999}"></asp:RegularExpressionValidator></td>
            </tr>
            <tr>
                <td style="height: 27px">
                </td>
                <td style="width: 714px; height: 27px;">
                    <asp:Button ID="Button3" runat="server" Text="Create" OnClick="Button3_Click" />
                    </td>
            </tr>
        </table>
        &nbsp;
        
    </asp:Panel>
    <asp:Panel ID="pnSearch" runat="server"    Width="100%" Visible="False" >
        <table class="table2" style="width: 100%">
            <tr>
                <td style="width: 30%">
                    Routes</td>
                <td style="width: 100px">
                    <asp:DropDownList ID="ddlRoutesSearch" runat="server" Width="100%" AutoPostBack="True">
                    </asp:DropDownList>
                    </td>
            </tr>
        </table>
        <asp:GridView ID="gvBranchesOnRoute" runat="server" CssClass="table2" DataSourceID="dsRoutes"
            Width="100%" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" OnSelectedIndexChanged="gvBranchesOnRoute_SelectedIndexChanged">
            <Columns>
                <asp:BoundField DataField="BranchName" HeaderText="Branches Name" />
                <asp:BoundField DataField="Location" HeaderText="Location" />
                <asp:BoundField DataField="Phone" HeaderText="Phone" />
                <asp:BoundField DataField="Number" HeaderText="Number" />
                <asp:TemplateField  HeaderText="Action">
                    <ItemTemplate>
                        <%# @"<a href='?act=edit&bID="+Eval("BranchID").ToString()+"&rID="+Eval("RouteID").ToString()+"'>Edit</a>" %>
                        <%# @" || <a href='?act=del&bID=" + Eval("BranchID").ToString() + "&rID=" + Eval("RouteID").ToString() + "&number="+ Eval("Number").ToString()+"' onclick='return conf()'>Delete</a>"%>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="dsRoutes" runat="server" ConnectionString="<%$ ConnectionStrings:ketnoi2 %>"
            SelectCommand="SELECT Branches.BranchID, Branches.BranchName, Branches.Location, Branches.Phone, Branches.CreatedDate, Branches.Status, BranchesOnRoute.RouteID, BranchesOnRoute.BranchID AS Expr1, BranchesOnRoute.Number FROM Branches INNER JOIN BranchesOnRoute ON Branches.BranchID = BranchesOnRoute.BranchID WHERE (BranchesOnRoute.RouteID = @rid) order by BranchesOnRoute.Number ">
            <SelectParameters>
                <asp:ControlParameter ControlID="ddlRoutesSearch" Name="rid" PropertyName="SelectedValue" />
            </SelectParameters>
        </asp:SqlDataSource>
        &nbsp;
    
    </asp:Panel>
    <asp:Panel ID="pnEdit" runat="server"    Width="100%" Visible="False" >
        <table class="table2" style="width: 100%">
            <tr>
                <td style="width: 30%">
                    Branches name</td>
                <td style="width: 70%">
                    <asp:Label ID="lblBranchesName" runat="server"></asp:Label>
                    <asp:Label ID="lblBrachID" runat="server" Visible="False"></asp:Label>
                    <asp:Label ID="lblRoutID" runat="server" Visible="False"></asp:Label></td>
            </tr>
            <tr>
                <td style="width: 30%">
                    Number</td>
                <td style="width: 70%">
                    <asp:TextBox ID="txtNumberEdit" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtNumberEdit"
                        Display="Dynamic" ErrorMessage="Please input number"></asp:RequiredFieldValidator><asp:RegularExpressionValidator
                            ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtNumberEdit"
                            Display="Dynamic" ErrorMessage="Only number" ValidationExpression="\d{0,999999999}"></asp:RegularExpressionValidator></td>
            </tr>
            <tr>
                <td style="width: 30%">
                </td>
                <td style="width: 70%">
                    <asp:Button ID="Button2" runat="server" Text="Update" OnClick="Button2_Click" /></td>
            </tr>
        </table>
    </asp:Panel>
    <script>
    function conf()
{
return confirm("Are you sure?");
}
    </script>
</asp:Content>
